package com.novoda.runbuddy.controller;

import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;

import com.novoda.runbuddy.R;
import com.novoda.runbuddy.activity.Calendar;
import com.novoda.runbuddy.activity.DebugSettings;
import com.novoda.runbuddy.activity.Stopwatch;
import com.novoda.runbuddy.activity.Today;
import com.novoda.runbuddy.provider.ActivityID;

public class OptionsMenuImpl implements IOptionsMenu {

	private Activity	activity;

	public OptionsMenuImpl(Activity activity) {
		this.activity = activity;
	}

	public void addAllActivitiesToMenu(Menu menu) {
		menu.add(0, 0, ActivityID.STOPCLOCK, R.string.goto_stopwatch);
		menu.add(0, 1, ActivityID.TODAYJOGS, R.string.goto_today);
		menu.add(0, 2, ActivityID.PASTJOGS, R.string.goto_pastjogs);
		menu.add(0, 3, ActivityID.MAKEMAP, R.string.goto_help);
		menu.add(0, 4, ActivityID.DBGSETTINGS, R.string.goto_debugSettings);
	}

	public void selectItem(MenuItem item) {
		switch (item.getItemId()) {

			case ActivityID.STOPCLOCK:
				switchToStopClock();
				break;

			case ActivityID.TODAYJOGS:
				switchToToday();
				break;

			case ActivityID.PASTJOGS:
				switchToPastJogs();
				break;

			case ActivityID.DBGSETTINGS:
				switchToDbgSettings();
				break;
		}

	}

	private void switchToStopClock() {
		Stopwatch.show(activity);
	}

	private void switchToToday() {
		Intent i = new Intent(activity, Today.class);
		activity.startActivityForResult(i, ActivityID.TODAYJOGS);
	}

	private void switchToPastJogs() {
		Intent i = new Intent(activity, Calendar.class);
		activity.startActivityForResult(i, ActivityID.PASTJOGS);
	}

	private void switchToDbgSettings() {
		Intent i = new Intent(activity, DebugSettings.class);
		activity.startActivityForResult(i, ActivityID.DBGSETTINGS);
	}

}
